const state = {
  lnikArr: [],
  isActive: -1
}
const mutations = {
  SET_LINK: (state, aLink) => {
    const fIndex = state.lnikArr.findIndex((item) => {
      return item.path === aLink.path
    })
    if (fIndex >= 0) {
      state.lnikArr.splice(fIndex, 1)
    }
    state.lnikArr.push(aLink)
  },
  DELETE: (state, index) => {
    state.lnikArr.splice(index, 1)
  },
  SET_ACTIVE(state, index) {
    state.isActive = index
  },
  CLEAR_LINK(state, arr) {
    state.lnikArr = arr
  }
}
const actions = {
  setLink(context, alink) {
    context.commit('SET_LINK', alink)
  },
  setActive(context, index) {
    context.commit('SET_ACTIVE', index)
  },
  delLink(context, index) {
    context.commit('DELETE', index)
  },
  clear(context) {
    context.commit('CLEAR_LINK', [])
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
